package cn.tedu.boot1001.controller;

import cn.tedu.boot1001.entity.Class;
import cn.tedu.boot1001.mapper.ClassMapper;
import cn.tedu.boot1001.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/class/") //后面的/可加可不加，会自动处理
public class ClassController {

    @Autowired
    ClassMapper mapper;

    @RequestMapping("select")
    public List<Class> select(){
        return mapper.select();
    }

    @RequestMapping("insert")
    public void insert(@RequestBody Class c){
        mapper.insert(c);
    }

    @Autowired
    StudentMapper stuedentMapper;
    @RequestMapping("delete")
    public void delete(int id){
        mapper.deleteById(id);
        //同时删除班级下的所有学生
        stuedentMapper.deleteByCid(id);
    }

    @RequestMapping("selectById")
    public Class selectById(int id){
        return mapper.selectById(id);
    }
}
